package net.kingborn.erp.data.controller;

import net.kingborn.core.controller.BaseController;
import net.kingborn.core.controller.Controller;
import net.kingborn.core.entry.Result;
import net.kingborn.erp.data.dao.Esp32Dao;
import net.kingborn.erp.data.model.Esp32;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Controller("/esp32")
public class Esp32DataController extends BaseController {

    @Autowired
    Esp32Dao esp32Dao;

    @GetMapping("/saveTh")
    public Result saveTh(@Param("t_wd") String t_wd, @Param("t_sd") String t_sd, @Param("t_name") String t_name, @Param("t_tr_sd") String t_tr_sd) {
        Result result = new Result();
        String t_id = UUID.randomUUID().toString().replaceAll("-", "");
        String t_date = new SimpleDateFormat("yyyyMMdd").format(new Date());
        String t_time = new SimpleDateFormat("HHmmssS").format(new Date());
        Esp32 esp32 = new Esp32();
        esp32.setT_date(t_date);
        esp32.setT_id(t_id);
        esp32.setT_name(t_name);
        esp32.setT_wd(t_wd);
        esp32.setT_sd(t_sd);
        esp32.setT_time(t_time);
        esp32.setT_tr_sd(t_tr_sd);
        esp32Dao.saveTh(esp32);
        return result;
    }


    @GetMapping("/queryTh")
    public Result queryTh() {
        Result result = new Result();
        List<Esp32> esp32s = esp32Dao.queryTh();
        result.setData(esp32s);
        return result;
    }


}
